package com.m3958.firstgwt.server.model;

import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import com.m3958.firstgwt.server.types.IHasSiteId;

import net.sf.json.JSONObject;

/**
 * siteId作为key，存储referer作为set。
 * 通过referer作为key，存储：访问时间，ip，等。列表。
 * 还是以referer作为key，存储计数器。
 * 一个程序例程定时转存数据。
 * @author jianglibo@gmail.com
 *
 */


@Entity
@Table(name="URL_STATISTICS", uniqueConstraints = { @UniqueConstraint(columnNames = {"siteId","referer"})})
@AttributeOverride(name="id",column=@Column(nullable = false,name="URL_STAT_ID"))
@NamedQueries({
	@NamedQuery(name="UrlStatistics_findUrlStatics",
			query="SELECT u FROM UrlStatistics AS u WHERE u.siteId = :siteId AND u.referer = :referer"),
	@NamedQuery(name="UrlStatistics_findSiteHitCount",
			query="SELECT SUM(u.hitCount) FROM UrlStatistics AS u WHERE u.siteId = :siteId")
})
public class UrlStatistics extends BaseModel<UrlStatistics> implements IHasSiteId{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public static class NamedQueries{
		public final static String FIND_URLSTATICS = "UrlStatistics_findUrlStatics";
		public final static String FIND_SITE_HITCOUNT = "UrlStatistics_findSiteHitCount";
	}
	
	private int siteId;
	
	private String referer;
	
	private int hitCount;
	

	@Override
	public JSONObject toJson() {
		return null;
	}

	@Override
	public void setSiteId(int siteId) {
		this.siteId = siteId;
	}

	@Override
	public int getSiteId() {
		return siteId;
	}

	public void setReferer(String referer) {
		this.referer = referer;
	}

	public String getReferer() {
		return referer;
	}

	public void setHitCount(int hitCount) {
		this.hitCount = hitCount;
	}

	public int getHitCount() {
		return hitCount;
	}

	@Override
	public String[] getJsonExcludes() {
		// TODO Auto-generated method stub
		return null;
	}

}
